#ifndef PEROSNALCHATROOM_H
#define PEROSNALCHATROOM_H

#include <QWidget>
#include"frienditem.h"
#include<QListWidgetItem>
#include<QUdpSocket>
#include"mysendmes.h"
#include"othersendmes.h"
#include"privateinfo.h"
namespace Ui {
class perosnalchatroom;
}

class perosnalchatroom : public QWidget
{
    Q_OBJECT

public:
    explicit perosnalchatroom(QWidget *parent = nullptr);
    ~perosnalchatroom();
    QHash<int,frienditem*> friendlist;    //listwidgetindex - frienditem
    QHash<QString,frienditem*> friendlistbyname;    //name   -   frienditem
    QHash<QString,QVector<mysendmes*>> ms;    //name  -  mysendmes
    QHash<QString,QVector<othersendmes*>> os;   //name - othersendmes
    int nextpos=0;
    QUdpSocket* uso;  //通过udpsocket进行网络通信
    privateinfo* pri;
    frienditem* curfriend;   //当前聊天的好友

    int mescurrow=0;
public:
    void initprivateinfo(privateinfo* pri);
    void initudpsocket();  //更新udp套接字
    void addonefriend(frienditem* fri);
    void deleteonefriend(QString name);
    void loadfriends(QHash<QString,frienditem*> friends);
    void loadfriendmes(QHash<QString,QVector<mysendmes*>> ms,QHash<QString,QVector<othersendmes*>> os);
    QVector<int> converttime(QString time);
    bool comparetime(QVector<int> r1,QVector<int> r2);
signals:
    void addonefriendmes(QString fri,QString content_type,QString content);
private slots:
    void on_textEdit_textChanged();

    void on_sendbtn_clicked();

    void on_friendlist_currentRowChanged(int currentRow);

private:
    Ui::perosnalchatroom *ui;
};

#endif // PEROSNALCHATROOM_H
